<?php

class Base {
  
  private static $connect;
  
  public  function __construct()
  {
  }
  
  private static function connect() {
    include_once('config/config.db.php');
    $db = DB::connect("$dbtype://$user:$pass@$host/$dbname");
    if(PEAR::isError($db)) {
	    throw new BaseException($db->getMessage());
    }
    return $db;
  }

  public static function getConnection() 
  {
    if (!(isset(self::$connect))) 
      {
        $db = self::connect();	
	self::$connect = $db;
      }
    return self::$connect;
  }
  

  public static function doUpdate($query) 
  {		
    $db = self::getConnection();
    $dbres=$db->query($query);
    if (Pear::isError($dbres)) 
      {
	throw new BaseException($dbres->getMessage());
      } 
    return $db->affectedRows();
  }
  
  public static function doSelect($query) 
  {
    $db = self::getConnection($conf_name);
    $dbres=$db->query($query);
    if (Pear::isError($dbres)) 
      {	
	throw new BaseException($dbres->getMessage());
      } 
    while ($row = $dbres->fetchRow(DB_FETCHMODE_ASSOC)) 
      {
	if (Pear::isError($dbres)) 
	  { 
	    throw new BaseException($dbres->getMessage());
	  }
	$allrows[]=$row;
      }
    return $allrows;
  }
}

?>
	


  
